package com.ft.sso.secrityauthor2sso.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

/**
 * @Author RenPu
 * @Date 2022/9/28 11:48
 * @Version 1.0
 * @Description: 集成oauth2所需的授权配置类（授权服务器）
 *
 *               //授权码模式
 **/

//@Configuration
//@EnableAuthorizationServer  //让授权服务器生效
public class AuthenticationServerConfig  extends AuthorizationServerConfigurerAdapter {

    @Autowired
    @Lazy
    private PasswordEncoder passwordEncoder;

//    @Autowired
//    private AuthenticationManager authenticationManager;

    //授权码模式
    //http:localhost:8086/oauth/authorize?response_type=code&client_id=client
    // &redirect_uri=http://www.baidu.com&scope=all



    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("client")
                .secret(passwordEncoder.encode("123456"))
                .accessTokenValiditySeconds(3600)
                .refreshTokenValiditySeconds(3600)
                .redirectUris("http://www.baidu.com")
                .scopes("all")
                .authorizedGrantTypes("authorization","implicit");


    }
}
